package com.tedu.ds.consumables.service.impl;

import com.tedu.ds.consumables.mapper.ConsumablesMapper;
import com.tedu.ds.consumables.pojo.dto.ConsumablesParam;
import com.tedu.ds.consumables.pojo.dto.ConsumablesQuery;
import com.tedu.ds.consumables.pojo.entity.Consumables;
import com.tedu.ds.consumables.pojo.vo.ConsumablesPage;
import com.tedu.ds.consumables.pojo.vo.ConsumablesVO;
import com.tedu.ds.consumables.service.ConsumablesService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class ConsumablesServiceImpl implements ConsumablesService {
    @Autowired
    private ConsumablesMapper consumablesMapper;
    @Override
    public void save(ConsumablesParam param) {
        Consumables consumables = new Consumables();
        BeanUtils.copyProperties(param,consumables);
        if(consumables.getId()==null){
            consumablesMapper.insert(consumables);
        }else{
            consumablesMapper.update(consumables);
        }
    }
    @Override
    public void deleteById(Long id) {
        consumablesMapper.deleteById(id);
    }

    @Override
    public ConsumablesPage select(ConsumablesQuery query) {
        List<ConsumablesVO> list = consumablesMapper.select(query);
        int total = consumablesMapper.count(query);
        ConsumablesPage page = new ConsumablesPage();
        page.setTotal(total);
        page.setList(list);
        return page;
    }
}
